home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 October: Mac OS SDK / Dev.CD Oct 97 SDK1.toast / Development Kits (Disc 1) / QuickDraw GX / Programming Stuff / Sample Code / Printing Samples / Extensions… / Back2Front ƒ / Back2Front.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-03-20  |  5.4 KB  |  213 lines  |  [TEXT/MPS ]

  1. /*________________________________________________________
  2.  
  3.     File: Back2Front.c
  4.  
  5.     C code for a page-reversing printing extension.
  6.  
  7.     Dave Hersey
  8.     Apple Developer Technical Support
  9.  
  10.      3/22/94 - dmh - Created.
  11.  
  12.     (Note: all functions are in the Mark menu.)
  13.     
  14. __________________________________________________________*/
  15.  
  16. #include "Back2Front.h"
  17.  
  18.  
  19. /*******************************************************************
  20.     InitGlobalData is used to initialize any global data we need to
  21.     in our initialize message override.  It's critical that you do
  22.     things this way, rather than access the data in the same scope
  23.     that you call NewMessageGlobals.  Otherwise, some compilers
  24.     will give you code that references an invalid A5 world.
  25.  
  26. ********************************************************************/
  27.  
  28. OSErr InitGlobalData()
  29. {
  30. // Initialize any global data here.
  31.     
  32.     return noErr;
  33. }
  34.  
  35.  
  36. /*******************************************************************
  37.     NewInitialize is our override for the GXInitialize message.  In
  38.     here, you shouldn't initialize anything directly-- call
  39.     InitGlobalData for that.  Once you create the A5 world with
  40.     NewMessageGlobals, you can access your global data just like
  41.     you were an application.  Whenever you're called, your global
  42.     data will be valid.
  43.     
  44. ********************************************************************/
  45.  
  46. OSErr NewInitialize()
  47. {
  48.     OSErr    err;
  49.  
  50. // Create an A5 world, and initialize our global data.
  51.  
  52.     err = NewMessageGlobals(A5Size(), A5Init);
  53.     
  54.     if (!err) err = InitGlobalData();
  55.     
  56.     return err;
  57. }
  58.  
  59.  
  60. /*******************************************************************
  61.     NewShutDown is our override for the GXShutDown message.  We
  62.     simply throw away our A5 world which we created in our
  63.     GXInitialize message override, NewInitialize.
  64.     
  65. ********************************************************************/
  66.  
  67. OSErr NewShutDown()
  68. {
  69.     DisposeMessageGlobals();
  70.     return noErr;
  71. }
  72.  
  73.  
  74. /*******************************************************************
  75.     NewImageDocument is our override for the GXImageDocument
  76.     message.  We check to see if we're enabled, and if so, print
  77.     our pages in the reverse order.
  78.  
  79. ********************************************************************/
  80.  
  81. OSErr NewImageDocument(gxSpoolFile aSpoolFile, void *imageData)
  82. {
  83.     OSErr                    err = noErr;
  84.     ExtensionCollection        extCollect;
  85.     gxFormat                theFormat;
  86.     long                    numPages;
  87.     long                    i;
  88.     
  89. // Try to retrieve our collection item.  If we can't find it, we'll
  90. // act as if the user had us turned off or on (as determined by
  91. // kDefaultSetting).
  92.  
  93.     err = GetJobCollectionItem(&extCollect, nil, kExtensionCollectionType,
  94.                                gxPrintingTagID);
  95.  
  96.     if (err)
  97.     {
  98.         extCollect.extTurnedOn = kDefaultSetting;
  99.         err = noErr;
  100.     }
  101.  
  102.  
  103. // If we're turned on, print the pages in the reverse order.
  104. //    Otherwise, just forward the message down the chain.
  105.  
  106.     if (extCollect.extTurnedOn)
  107.     {
  108.         theFormat = GXNewFormat(GXGetJob());
  109.         err = Send_GXCountPages(aSpoolFile, &numPages);
  110.     
  111.         for (i = numPages; (err == noErr) && (i > 0); i--)
  112.             err = Send_GXImagePage(aSpoolFile, i, theFormat, imageData);
  113.         
  114.         GXDisposeFormat(theFormat);
  115.     }
  116.     else
  117.         err = Forward_GXImageDocument(aSpoolFile, imageData);
  118.     
  119.     return err;
  120. }
  121.  
  122.  
  123. /*******************************************************************
  124.     NewJobPrintDialog is our override for GXJobPrintDialog.  All we
  125.     do is set up our panel and then forward the message.
  126.     
  127. ********************************************************************/
  128.  
  129. OSErr NewJobPrintDialog(gxDialogResult *dlogResult)
  130. {
  131.     OSErr    err;
  132.     
  133.     err = SetUpPrintPanel();
  134.  
  135.     if (!err)
  136.         err = Forward_GXJobPrintDialog(dlogResult);
  137.     
  138.     return err;
  139. }
  140.  
  141.  
  142. /*******************************************************************
  143.     SetUpPrintPanel sets up our print panel, adding a default
  144.     ExtensionCollection item to the job collection.  This
  145.     collection item has the values we'll use to set up our panel's
  146.     controls.
  147.     
  148. ********************************************************************/
  149.  
  150. OSErr SetUpPrintPanel()
  151. {
  152.     OSErr                    err;
  153.     gxPanelSetupRecord        panelSetupRec;
  154.     ExtensionCollection        extConfig;
  155.  
  156. // Try to find our collection item.
  157.  
  158.     err = GetCollectionItem(GXGetJobCollection(GXGetJob()),
  159.                             kExtensionCollectionType,
  160.                             gxPrintingTagID,
  161.                             nil,
  162.                             &extConfig);
  163.  
  164.  
  165. // If we don't have an item in the job collection yet, store our default
  166. // settings in it.
  167.  
  168.     if (err == collectionItemNotFoundErr)
  169.     {
  170.         extConfig.extTurnedOn = kDefaultSetting;
  171.     
  172.         err = AddCollectionItem(GXGetJobCollection(GXGetJob()),
  173.                                 kExtensionCollectionType,
  174.                                 gxPrintingTagID,
  175.                                 sizeof(ExtensionCollection),
  176.                                 &extConfig);
  177.  
  178.         nrequire(err, HaveCollectionMgrError);
  179.     }
  180.  
  181.  
  182. // Now, set up the panel.
  183.  
  184.     panelSetupRec.panelResId        = r_ExtensionPanel;        // which panel resource?
  185.     panelSetupRec.resourceRefNum    = GXGetMessageHandlerResFile(); // where is it?
  186.     panelSetupRec.refCon            = 0;                       // we don't use this.
  187.     panelSetupRec.panelKind            = gxExtensionPanel;     // This is an extension panel.
  188.  
  189.     err = GXSetupDialogPanel(&panelSetupRec);
  190.  
  191.  
  192. HaveCollectionMgrError:
  193.     
  194.     return err;
  195. }
  196.  
  197.  
  198. /*******************************************************************
  199.     GetJobCollectionItem is a generic routine that retrieves a
  200.     collection item from the job collection.
  201.     
  202. ********************************************************************/
  203.  
  204. OSErr GetJobCollectionItem(void *collectItem, long *collectSize,
  205.                            OSType collectType, short collectID)
  206. {
  207.     return GetCollectionItem(GXGetJobCollection(GXGetJob()),
  208.                              collectType,
  209.                              collectID,
  210.                              collectSize,
  211.                              collectItem);
  212. }
  213.